#include <iostream>
#include <map>
#include <cstring>
using namespace std;

int main()
{
    map<const char *, const char *> mp;
    map<const char *, const char *>::iterator iter;
    const char key[3][20]={"img","system","ip"};
    const char value[3][20]={"d:/a.img","win7","193.68.6.3"};
    // make_pair 插入
    for(int i = 0; i < 2; i++){
        mp.insert(make_pair(key[i], value[i]));
    }
    // pair<const char*, const char*> 插入
    mp.insert(pair<const char*, const char *>(key[2], value[2]));
    //数组插入方式
    mp["addr"] = "中国";
    // 迭代器取出元素
    for(iter = mp.begin(); iter != mp.end(); iter++)
    {
        cout << iter->first << "\t" << iter->second << endl;
    }
    char key1[20];
    cout << "请输入按key查找：";
    cin.getline(key1,20);
    // 查找元素
    for(iter = mp.begin(); iter != mp.end(); iter++)
    {
        if(strcmp(iter->first, key1) == 0){
            cout << "查找结果" << iter->first << "\t" << iter->second << endl;
        }
    }
}
